﻿using ShopManagement.Model.EF;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ShopManagement
{

    public partial class FormUser : Form
    {
        private UserService userService = new UserService();
        private int currentUserId;
        public FormUser()
        {
            InitializeComponent();
            LoadUserInfo();
        }
        private void LoadUserInfo()
        {
            var users = userService.GetAll();
            if (users.Any())
            {
                // 假设我们只显示第一个用户的信息
                Users user = userService.GetUserById(1);
                textBox1.Text = user.UserName;
                textBox2.Text = user.UserNumber;
                textBox3.Text = user.UserPassword;
                textBox4.Text = user.UserEmail;
                // 保存当前用户的UserID，以便编辑时使用
                currentUserId = user.UserID;
            }
}
    private void FormUser_Load(object sender, EventArgs e)
        {
            
        }

        private void butEdit_Click(object sender, EventArgs e)
        {
            UserEdit userEditForm = new UserEdit(currentUserId);
            userEditForm.LoadUserInfo(textBox1.Text, textBox4.Text, textBox3.Text, textBox2.Text);
            if (userEditForm.ShowDialog() == DialogResult.OK)
            {
                LoadUserInfo(); // 重新加载用户信息
            }
        }

        private void butCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
